<?php
// print_r($_POST);print_r($_FILES);exit;
include '../class/Uploader.class.php';
//判断上传的类型
switch($_POST['upload_mth']){
    case '0':
        $config = array(//图片
            'savePath' => '/databak/images/'.$_SESSION['account'],
            'maxSize' => 1024*5,
            "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"),
            'upType' => 'upfile'			
        );
        break;
    case '1':
         $config = array(//音频
            'savePath' => '/databak/images/'.$_SESSION['account'],
            'maxSize' => 2*1024,
            'allowFiles' => array('.mp3', '.aac', '.wma'),
            'upType' => 'upfile_music'
        );
        break;
    case '2':
        $config = array(//视频
            'savePath' => '/databak/images/'.$_SESSION['account'],
            'maxSize' => 5*1024,
            'allowFiles' => array('.mov', '.mp4', '.avi', '.mkv', '.flv'),
            'upType' => 'upfile_video'
        );
        break;
    case '3':
         $config = array(//360全景
            'savePath' => '/databak/images/'.$_SESSION['account'],
            'maxSize' => 3*1024,
            'allowFiles' => array('.zip', '.rar'),
            'upType' => 'upfile_allvideo'
        );
        break;
    default:
        break;
}

// echo $config['upType'];exit;
// print_r($_FILES);
// exit;
if(!$config || !$_SESSION['sid'])
    die('出错了');

$up = new Uploader($config['upType'], $config);
$info = $up->getFileInfo();
// print_r($info);
/*
*Uploader注释
*getFolder() 只是目录名 不包含文件名
*getName() 新的文件名(方法)
*fileName  新的文件名(属性)
*getRealName() 新的文件名 前缀
*getFileExt 原后缀
*前缀+后缀为新的文件完整名
*$info 得到的返回值
* "originalName" => $this->oriName ,
            "name"         => $this->fileName ,
            "url"          => $url ,
            "size"         => $this->fileSize ,
            "type"         => $this->fileType ,
            "state"        => $this->stateInfo,
            "width"        => $width,
            "height"       => $height,
*/
$index = $_REQUEST['upload_mth'];
//print_r($_REQUEST);
if($info['state']=='SUCCESS') {
//    $path = $config['upType'] == 'upfile_img' ? $up->smart_resize_image(350,235) : $info['url'];//不知道怎么改 先屏蔽了
    $path = $up->smart_resize_image(350,235);
    $path = str_replace('/databak/images/', 'http://images.12301.cc/', $path);
    $title = $info['originalName'];
    $srcipt = <<< HTML
    <script>
    parent.jQuery("input.thumb_img").eq($index).val('http://www.12301.cc/{$path}');
    parent.jQuery("img.preview").eq($index).attr('src','$path').attr('title','$title');
    parent.jQuery("img.lnk_prv").eq($index).attr('href','$path');
    parent.jQuery('.waitingUpload').eq($index).empty().text('上传成功！');
    </script>
HTML;
}
else {
    $srcipt = "<script>alert('".$info['state']."');parent.$('#waitingUpload').empty().text('".$info['state']."');</script>";
}
echo $srcipt;t;